import React from "react";
import cookie from "react-cookie";
import {Constant} from "../utils/BaseConstant";
class StaffItem extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        var {typeName, staffVos} = this.props.item;
        if (staffVos.length > 0) {
            return (
                <li>
                    <div className="management-staff-item-title-container">
                        <hr/>
                        <div>{typeName}</div>
                        <hr/>
                    </div>
                    <ul>
                        {
                            staffVos.map((item, index) => {
                                return (
                                    <div key={index}>
                                        <li>
                                            <div className="staff-item-container">
                                                <div
                                                    onClick={this._goToStaffDetail.bind(this, item)}>{item.userName}</div>
                                                <div
                                                    onClick={this._goToStaffDetail.bind(this, item)}>{item.userAccount}</div>
                                                <div
                                                    onClick={this._goToStaffDetail.bind(this, item)}>{item.bindingStatus == 0 ? item.bindingDesc : ""}</div>
                                            </div>
                                            <hr className="base-divide-line"/>
                                        </li>
                                    </div>
                                )
                            })

                        }
                    </ul>
                </li>
            );
        } else {
            let disabled = "", unclikeable = "";
            let userRight = cookie.load("userRight");
            if (cookie.load("userRight") != 1) {
                disabled = "disabled";
                unclikeable = "unclikeable";
            }
            return (
                <div className="management-staff-container">
                    <div className="management-staff-header">
                        <div className="management-staff-header-img"></div>
                        <div>员工在哪里</div>
                    </div>
                    <div className="management-staff-button-group">
                        <button
                            onClick={this._addStaff.bind(this, Constant.CASHIER)}>+收银员
                        </button>
                        <div className="management-staff-space"></div>
                        <button
                            onClick={this._addStaff.bind(this, Constant.ACCOUNTANT)}>+财务
                        </button>
                        <div className="management-staff-space"></div>
                        <button className={unclikeable}
                                disabled={disabled}
                                onClick={this._addStaff.bind(this, Constant.ADMIN)}>
                            +管理员
                        </button>
                    </div>
                    <div className="management-staff-bottom">
                        <div>
                            <div className="management-staff-bottom-img"></div>
                        </div>
                        <div>
                            <div>收银员权限：</div>
                            <div>1.店铺收款二维码 2.查看每天交易额，交易流水记录 3.通知提示每笔收款到账</div>
                            <div>管理员权限：</div>
                            <div>1.管理员工 2.店铺收款二维码 3.查看、导出交易流水记录 4.通知提示每笔收款到账</div>
                            <div>财务权限：</div>
                            <div>1.查询交易清单 2.导出交易清单</div>
                        </div>
                    </div>
                </div>
            )
        }
    }

    _goToStaffDetail(staffVos) {
        let {typeId, typeName} = this.props.item;
        var editStaffInfo = {
            typeId: typeId,
            typeName: typeName,
            userName: staffVos.userName,
            userAccount: staffVos.userAccount,
            bindingId: staffVos.bindingId,
            bindingStatus:staffVos.bindingStatus
        };
        cookie.save("editStaffInfo", editStaffInfo);
        let shopNo = this.props.shopNo;
        window.location.href = "/#/pay/editStaff?shopNo=" + shopNo;
    }

    _addStaff(type) {
        let {shopNo} = this.props.item;
        //alert("shopNo:" + shopNo);
        window.location.href = "/#/pay/addEmployee?staffType=" + type + "&shopNo=" + shopNo;
    }

}
export default StaffItem;